﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.Common.ConsistentHash
{
    /// <summary>
    /// A server node in the node space
    /// </summary>
    public class Node : NodeList<Node>
    {
        public string Address { get; set; }
        public string Port { get; set; }
        public bool IsLive = true;

        public override string ToString()
        {
            return Address + ":" + Port;
        }

        /// <summary>
        /// HashCode
        /// </summary>
        /// <returns></returns>
        public uint HashCode()
        {
            return HashFactory.Calculate(ToString());
        }

        public string Value { get; set; }

        #region constructor
        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public Node(string address, string port)
        {
            Address = address;
            Port = port;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        /// <param name="isLive"></param>
        public Node(string address, string port, bool isLive)
        {
            Address = address;
            Port = port;
            IsLive = isLive;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        /// <param name="nodes"></param>
        /// <param name="replicate"></param>
        public Node(string address, string port, IEnumerable<Node> nodes, int replicate)
            : base(nodes, replicate)
        {
            Address = address;
            Port = port;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="replicate"></param>
        public Node(IEnumerable<Node> nodes, int replicate)
            : base(nodes, replicate)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nodes"></param>
        public Node(IEnumerable<Node> nodes)
            : base(nodes)
        {

        }
        #endregion



    }
}
